package com.sense.kukoo.common.wiget

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import com.sense.kukoo.lib_logger.LoggerManager

class FocusFrameLayout:FrameLayout {

    private val TAG = FocusFrameLayout::class.simpleName
    private val isDebug = false

    private var onTouchDown: ()->Unit = {}

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
        initView()
    }

    private fun initView(){}

    override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
        if (isDebug) {
            LoggerManager.e(TAG, "dispatchTouchEvent event=${ev?.action}")
        }
        if(ev?.action == MotionEvent.ACTION_DOWN){
            onTouchDown()
        }
        return super.dispatchTouchEvent(ev)
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        if (isDebug) {
            LoggerManager.e(TAG, "onInterceptTouchEvent event=${ev?.action}")
        }
        return super.onInterceptTouchEvent(ev)
    }

    fun setOnTouchDown(action: ()->Unit){
        onTouchDown = action
    }

}